<?php

namespace Home\Controller;

use Think\Controller;

class MessageController extends Controller{

    public function index(){

        $this->display();
    }

    public function add(){
        if (IS_POST) {
            $data = $result = array();
            $data['name'] = I('post.name');
            $data['email'] = I('post.email');
            $data['mobile']  = I('post.mobile');
            $data['company'] = I('post.company');
            $data['message'] = I('post.message');
            $data['create_time'] = NOW_TIME;

            if (M('message')->add($data)) {
                $result['code'] = 200;
                $result['message'] = '发送成功';
                echo json_encode($result);exit;
            } else {
                $result['code'] = 4001;
                $result['message'] = '发送失败';
                echo json_encode($result);exit;
            }

        }else{
            $result['code'] = 4001;
            $result['message'] = '发送失败';
            echo json_encode($result);exit;
        }
    }
}
